//JS
layui.use(['element', 'layer', 'util'], function () {
    var element = layui.element
        , layer = layui.layer
        , util = layui.util
        , $ = layui.$;
    //头部事件
    util.event('lay-header-event', {
        //左侧菜单事件
        menuLeft: function (othis) {
            layer.msg('展开左侧菜单的操作', {icon: 0});
        }
        , menuRight: function () {
            layer.open({
                type: 1
                , content: '<div style="padding: 15px;">处理右侧面板的操作</div>'
                , area: ['260px', '100%']
                , offset: 'rt' //右上角
                , anim: 5
                , shadeClose: true
            });
        }
    });
});
var searchButton = document.getElementById("searchButton");
searchButton.onclick = function () {
    let searchType = document.getElementById("schoolOrPro");
    if (searchType.innerHTML.includes("学校")) {

        /*搜索对应的学校*/
        location.replace("/yewen/search/bySchool?school=" +$("#schoolValue").val()+"&id="+$("#id").html());

        // $.ajax({
        //     type: "GET",
        //     url:"http://localhost:8080/yewen/search/bySchool?school="+$("#searchButton").val(),
        //     success:function (data) {
        //
        //     },
        //     error:function (error) {
        //
        //     }
        // })
    } else {

    }
}
layui.use('dropdown', function () {
    var dropdown = layui.dropdown
    dropdown.render({
        elem: '#dropBtn',
        trigger: 'hover',
        data: [
            {
                title: '学校',
                id: "schoolChosen",
                name: "schoolChosen"
            },
            {
                title: '专业',
                id: "proChosen",
                name: "proChosen"
            }
        ],
        click: function (object) {
            var id = object.id;
            var btnText = document.querySelector("#dropBtn span");
            if (id == "schoolChosen") {
                btnText.innerHTML = "学校";
            } else {
                btnText.innerHTML = "专业";
            }

        }
    })
})
function refreshUniversity() {
    $.ajax({
        url:gOptions.defaultURLPrefix+"/yewen/ranking/getUniversityRanking",
        type: "GET",
        contentType:"application/x-www-form-urlencoded",
        dataType:"json",
        success:function (result) {
            let data = JSON.parse(result.data);
            let legends = $("#universityRanking");
            let index = 1;
            legends.html("");
            let rankingTip = $('<legend/>',{"style":"margin: auto; padding: 0 !important;"});
            rankingTip.html("高校——热度");
            legends.append(rankingTip);
            $.each(data,function (name,value) {
                let legend = $('<legend/>');
                legend.html(index++ +"."+name+"——"+value);
                legends.append(legend);
            })
        }
    })
}
function refreshMajor() {
    $.ajax({
        url:gOptions.defaultURLPrefix+"/yewen/ranking/getMajorRanking",
        type: "GET",
        contentType:"application/x-www-form-urlencoded",
        dataType:"json",
        success:function (result) {
            let data = JSON.parse(result.data);
            let legends = $("#majorRanking");
            let index = 1;
            legends.html("");
            let rankingTip = $('<legend/>',{"style":"margin: auto; padding: 0 !important;"});
            rankingTip.html("专业——热度");
            legends.append(rankingTip);
            $.each(data,function (name,value) {
                let legend = $('<legend/>');
                legend.html(index++ +"."+name+"——"+value);
                legends.append(legend);
            })
        }
    })
}
refreshUniversity();
refreshMajor();